/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** findMatrix(int* nums, int numsSize, int* returnSize, int** returnColumnSizes)
{
    // 计数数组，假设数字范围为0到200
    int count[201] = {0};
    int max_row = 0;

    // 统计每个数字的出现次数
    for (int i = 0; i < numsSize; i++) 
    {
        count[nums[i]]++;
        // 更新最大行数，最大行数为出现最多的数字的次数
        max_row = fmax(max_row, count[nums[i]]);
    }

    // 创建返回的二维数组
    int **res = (int **)malloc(max_row * sizeof(int *));
    (*returnColumnSizes) = (int *)malloc(max_row * sizeof(int));
    
    // 遍历每一行
    for (int i = 0; i < max_row; i++) 
    {
        // 为每一行分配内存
        res[i] = (int *)malloc(201 * sizeof(int));
        int cur_col = 0; // 当前列的计数

        // 遍历计数数组并填充二维数组
        for (int j = 0; j < 201; j++) 
        {
            if (count[j] > 0) 
            {
                // 将数字添加到当前行，并减少其计数
                res[i][cur_col++] = j;
                count[j]--;
            }
        }
        // 存储当前行的列数
        (*returnColumnSizes)[i] = cur_col;
    }
    *returnSize = max_row;
    return res;

}